package org.itcast.travel.controller;

import lombok.extern.slf4j.Slf4j;
import org.itcast.travel.pojo.Comment;
import org.itcast.travel.pojo.Result;
import org.itcast.travel.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * wangcong
 * 2024/12/26 20:01
 */
@RestController
@RequestMapping("/comment")
@Slf4j
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping
    public Result insertComment(@RequestBody Comment comment) {
        log.info("评论发布:{}",comment);
        commentService.insertOne(comment);
        return Result.success();
    }

    @DeleteMapping("/{commentId}")
    public Result deleteComment(@PathVariable Integer commentId) {
        log.info("评论删除:{}",commentId);
        commentService.deleteComment(commentId);
        return Result.success();
    }

    @PutMapping("/like/{commentId}/{userId}")
    public Result likeComment(@PathVariable Integer commentId, @PathVariable Integer userId) throws Exception {
        log.info("评论点赞:{},{}",commentId,userId);
        commentService.likeComment(commentId,userId);
        return Result.success();
    }

    @GetMapping("/{blogId}")
    public Result getComment(@PathVariable Integer blogId) {
        log.info("获取该博客下的所有blogId:{}",blogId);
        List<Comment> commentList =commentService.getCommentList(blogId);
        return Result.success(commentList);
    }

}
